package com.example.lab2;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.TextView;

public class MainActivity extends Activity {

	public static int createdCnt = 0, startedCnt = 0, resumedCnt = 0;
	public final String CREATED_CNT="createdCnt", STARTED_CNT="startedCnt", RESUMED_CNT="resumedCnt";
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// Restore state
		if(savedInstanceState != null) {
			createdCnt = savedInstanceState.getInt(CREATED_CNT);
			startedCnt = savedInstanceState.getInt(STARTED_CNT);
			resumedCnt = savedInstanceState.getInt(RESUMED_CNT);
		}
		setContentView(R.layout.activity_main);
		
		createdCnt ++;
		TextView createdView = (TextView) this.findViewById(R.id.created_count);
		createdView.setText(getString(R.string.created_count) + createdCnt);
		

	}
	@Override
	protected void onStart() {
		super.onStart();
		startedCnt ++;
		TextView startedView = (TextView) this.findViewById(R.id.started_count);
		startedView.setText(getString(R.string.started_count) + startedCnt);
	}
	
	@Override
	protected void onResume() {
		super.onResume();
		resumedCnt ++;
		TextView resumedView = (TextView) this.findViewById(R.id.resumed_count);
		resumedView.setText(getString(R.string.resumed_count) + resumedCnt );
	}
	@Override
	protected void onPause() {
		super.onPause();
	}
	
	@Override
	protected void onStop() {
		super.onStop();
	}
	
	@Override
	protected void onDestroy() {
		super.onDestroy();
	}
 
	@Override
	protected void onSaveInstanceState(Bundle savedInstanceState) {
		savedInstanceState.putInt(CREATED_CNT, createdCnt);
		savedInstanceState.putInt(STARTED_CNT, startedCnt);
		savedInstanceState.putInt(RESUMED_CNT, resumedCnt);
		
		super.onSaveInstanceState(savedInstanceState);
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	}
	
	public void openNewActivity(View view) {
		// Open new activity in response to button click.
		Intent intent = new Intent(this, OtherActivity.class);
		startActivity(intent);
	}

}
